package com.aaa.marketing.controller.api;
/**
 * Date:2023/3/2
 * Author：臣哥哥
 * Description:
 */

import com.aaa.entity.Advertise;
import com.aaa.marketing.service.AdvertiseService;
import com.aaa.security.annotation.HasPermission;
import com.aaa.security.annotation.MyLog;
import com.aaa.util.UploadUtil;
import com.aaa.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author     ：Xiaochen
 * @date       ：Created in 2023/3/2 10:59
 * @description：
 * @modified By：
 * @version:
 */
@Api(value = "marketing/api/advertise", tags = {"广告控制"})
@RestController
@RequestMapping("marketing/api/advertise")
public class ApiAdvertiseController {
    @Autowired
    private AdvertiseService advertiseService;


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "Advertise", name = "advertise", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @HasPermission(value = "advertise:search")
    @MyLog(title = "查询所有广告管理")
    @RequestMapping("select")
    @ResponseBody
    public Result list(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize, @RequestBody Advertise advertise){
        return advertiseService.selectAll(currentPage,pageSize,advertise);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Advertise", name = "advertise", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @HasPermission(value = "advertise:add")
    @MyLog(title = "添加广告管理")
    @PostMapping("insert")
    public Result insert(@RequestBody Advertise advertise){
        return advertiseService.insert(advertise);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Advertise", name = "advertise", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @HasPermission(value = "advertise:modify")
    @MyLog(title = "修改广告管理")
    @PostMapping("update")
    public Result update(@RequestBody Advertise advertise){
        return advertiseService.update(advertise);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @HasPermission(value = "advertise:del")
    @MyLog(title = "删除广告管理")
    @GetMapping("delete")
    public Result delete(Integer id){
        return advertiseService.delete(id);
    }

    /**
     *头像上传
     * @param file
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form", dataType = "file", name = "file", value = "", required = true)
    })
    @ApiOperation(value = "头像上传", notes = "头像上传")
    @MyLog(title = "头像上传")
    @RequestMapping("/upload")
    @ResponseBody
    public Result upload(MultipartFile file)throws Exception {
        String path = UploadUtil.ossUpload(file);
        return new Result(2000, "添加成功", path);
    }
/**
 * @author JYH
 * @date 2023/3/3 15:56
 * @description - 修改上线状态
 * @param id
 * @param status
 */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "id", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "status", value = "", required = true)
    })
    @ApiOperation(value = "- 修改上线状态", notes = "- 修改上线状态", httpMethod = "POST")
    @PostMapping("/updateStatus")
    @MyLog(title = "修改上线状态")
    public Result updateStatus(Integer id,Integer status){
        return advertiseService.updateStatus(id,status);
    }

    /**
     * @author JYH
     * @date 2023/3/3 16:13
     * @description - 查询广告位置上线的广告数
     * @param positionId
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "positionId", value = "", required = true)
    })
    @ApiOperation(value = "- 查询广告位置上线的广告数", notes = "- 查询广告位置上线的广告数", httpMethod = "POST")
    @PostMapping("/selectCount")
    public Result updateStatus(Integer positionId){
        return advertiseService.selectCount(positionId);
    }

    /**
     * @author JYH
     * @date 2023/3/3 16:42
     * @description - 查询新闻位置最大广告数
     * @param positionId
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "positionId", value = "", required = true)
    })
    @ApiOperation(value = "- 查询新闻位置最大广告数", notes = "- 查询新闻位置最大广告数", httpMethod = "POST")
    @PostMapping("/selectMaxCount")
    public Result selectMaxCount(Integer positionId){
        return advertiseService.selectMaxCount(positionId);
    }


}